The OpenPNM GenericNetwork objects (e.g. Cubic, Voronoi, etc) have methods that let you query the connected pores and throats. This tutorial will explain how these work and illustrate why they are useful.
In [1]:
import openpnm as op
import numpy as np
np.random.seed(10)
%matplotlib inline
ws = op.Workspace()
ws.settings["loglevel"] = 40
In [2]:
pn = op.network.Cubic(shape=[4, 4, 1])
The following examples are relatively trivial, but their intention is to illustrate the different functions and options. More realistic use cases will be presented further down.
Start by finding all pores on the 'left' and 'front'
In [3]:
P_left = pn.pores('left')
P_bottom = pn.pores('front')
In [4]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey')
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
We'll merge these pores into a single set, and explore the different ways to find neighbors to this set. Note that the pore at [x,y] = [1.5, 1.5] has two neighbors (one 'bottom' and one 'left').
In [5]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey')
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
In [6]:
Ps = pn.pores(['left', 'front'])
print(Ps)
Ps = pn.find_neighbor_pores(pores=Ps, mode='or')
print(Ps)
In [7]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, Ps, c='green', marker='s', fig=fig)
Finds all pores with exactly one connection to the input pores
Given a set of pores find the pores that are neighbors of one and only one of the input pores. This is called XOR, or 'exclusve_or' because it finds the pores that are neigbhors to the 'bottom' or the 'left', but not both.
In [8]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey')
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
In [9]:
Ps = pn.pores(['left', 'front'])
print(Ps)
Ps = pn.find_neighbor_pores (pores=Ps, mode='xor')
print(Ps)
In [10]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, Ps, c='green', marker='s', fig=fig)
In [11]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey')
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
In [12]:
Ps = pn.pores(['left', 'front'])
print(Ps)
Ps = pn.find_neighbor_pores(pores=Ps, mode='xnor')
print(Ps)
In [13]:
#NBVAL_IGNORE_OUTPUT
fig = op.topotools.plot_coordinates(pn, Ps, c='green', marker='s', fig=fig)
In [14]:
##NBVAL_IGNORE_OUTPUT
Ps = pn.pores(['left', 'front'])
Ts = pn.find_neighbor_throats(pores=Ps, mode='or')
fig = op.topotools.plot_connections(pn, Ts)
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
ax = fig.gca()
ax.set_xlim(0.25, 3.75)
ax.set_ylim(0.25, 3.75)
Out[14]:
In [15]:
##NBVAL_IGNORE_OUTPUT
Ps = pn.pores(['left', 'front'])
Ts = pn.find_neighbor_throats(pores=Ps, mode='xnor')
fig = op.topotools.plot_connections(pn, Ts)
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
ax = fig.gca()
ax.set_xlim(0.25, 3.75)
ax.set_ylim(0.25, 3.75)
Out[15]:
In [16]:
##NBVAL_IGNORE_OUTPUT
Ps = pn.pores(['left', 'front'])
Ts = pn.find_neighbor_throats(pores=Ps, mode='xor')
fig = op.topotools.plot_connections(pn, Ts)
fig = op.topotools.plot_coordinates(pn, pn.Ps, c='lightgrey', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_left, c='red', marker='*', fig=fig)
fig = op.topotools.plot_coordinates(pn, P_bottom, c='blue', marker='.', fig=fig)
ax = fig.gca()
ax.set_xlim(0.25, 3.75)
ax.set_ylim(0.25, 3.75)
Out[16]: